package org.springframework.boot;

import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

public class Step6 {

    public static void main(String[] args) throws IOException {
        SpringApplication app = new SpringApplication();
        ApplicationEnvironment env = new ApplicationEnvironment();

        env.getPropertySources().addLast(new ResourcePropertySource(new ClassPathResource("step4.properties")));

        User user = Binder.get(env).bind("user", User.class).get();
        System.out.println(user.getFirstName());

        User user1 = new User();
        Binder.get(env).bind("user", Bindable.ofInstance(user1));
        System.out.println(user1.getMiddleName());
    }

    static class User{
        private String firstName;
        private String middleName;
        private String lastName;

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public void setMiddleName(String middleName) {
            this.middleName = middleName;
        }

        public void setLastName(String lastName) {
            this.lastName = lastName;
        }

        public String getFirstName() {
            return firstName;
        }

        public String getMiddleName() {
            return middleName;
        }

        public String getLastName() {
            return lastName;
        }
    }
}
